<?php
	session_start();
	session_destroy();

	$hostname = $_SERVER['HTTP_HOST'];
	$path = dirname($_SERVER['PHP_SELF']);

	updateLstModifiedTimeOfUser();
	header('Location: http://'.$hostname.($path == '/' ? '' : $path).'/index.php');
	
	
function updateLstModifiedTimeOfUser(){

	// Datenbankverbindung aufbauen
	$db = new mysqli('localhost', 'root', '', 'cityguide');
	if (mysqli_connect_errno()) {
    	printf("Connect failed: %s\n", mysqli_connect_error());
    	exit();
	}
	
	$query = "UPDATE LOGIN, USER SET LOGIN.lastLogin = NOW() where USER.emailaddress = LOGIN.username and USER.firstname = ?";
	if ($stmt = $db->prepare($query)) {  		
  		$stmt->bind_param('s', $_SESSION['username']);
  		$stmt->execute();
	}
	
	// Statement schliessen
	$stmt->close();
	
	// Datenbankverbindung schliesssen
	$db->close();
}

?>